<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">
				<a-search :isOk="true" @change="searchChange" />
			</block>
		</cu-custom>
		<a-scroll :request="get" ref="aScroll" :parm="{pageSize:30}">
			<template #item="{row:x,index}">
				<a-list :value="{...x,index}" @click="itemClick">
					<template #default="{row}">
						<a-list v-if="!!(teacherList[index] || []).length" :hide-icon="true" :value="x" v-for="(x,kl) in teacherList[index]" :key="index+'-'+kl">
							<template #right>
								<text class="iconfont icon-bianji" @click="go(x)"></text>
							</template>
						</a-list>
						<view v-if="!(teacherList[index] || []).length" style="text-align: center;line-height: 3em;font-size: 12px;color: #000;">没有数据</view>
					</template>
				</a-list>
			</template>
		</a-scroll>
	</view>
</template>

<script>
	import {stringObject} from '@/a/utils/api.js';
	export default {
		//上拉触底
		onReachBottom() {
			this.$refs.aScroll.lower();
		},
		//下拉刷新
		onPullDownRefresh() {
			this.$refs.aScroll.get(true).then(res => {
				uni.stopPullDownRefresh();
			});
		},
		data() {
			return {
				stringObject,
				searchText: "",
				teacherList: []
			}
		},
		methods: {
			get(parm = {}) {
				return this.$http.post('/api/v1/dept/findDeptPage', {
					...parm,
					name: this.searchText
				}).then(result => {
					return {
						total: result.totalSize,
						data: result.results.map(x => {
							return {
								...x,
								img: require('./1.png')
							}
						})
					}
				});
			},
			searchChange(e) {
				this.searchText = e;
				this.$refs.aScroll.get(true);
			},
			async itemClick(...e) {
				const [value, than] = e;
				if (this.teacherList[value.index]) return;
				const result = await this.$http.get('/api/v1/deptTeacher/selectDeptTeachers', {
					deptId: value.id
				}).finally(than.$loading({
					msg: '获取中'
				}));
				this.teacherList.splice(value.index, 0, result.map(x => {
					return {
						...x,
						img: this.$http.imgUrl + x.photo,
						sonTitle: x.telephone
					}
				}));
			},
			go(x){
				uni.navigateTo({
					url:`./edit${stringObject(x)}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.icon-bianji {
		font-size: 42px;
		margin: 0 5px;
		color: #0055ff;
	}
</style>
